<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try {
            ace.settings.check('breadcrumbs', 'fixed')
        } catch (e) {
        }
    </script>
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="<?php echo Yii::app()->createUrl('site/index') ?>">Bảng điều khiển</a>
        </li>

        <li>
            <a href="<?php echo Yii::app()->createUrl('contract/list') ?>">Hợp đồng</a>
        </li>
        <li class="active">Thêm mới hợp đồng</li>
    </ul>
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            Hợp đồng
            <small>
                <i class="icon-double-angle-right"></i>
                Thêm mới hợp đồng
            </small>
        </h1>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <?php $form = $this->beginWidget('CActiveForm', array(
                'id' => 'contract-form',
                'enableAjaxValidation' => true,
                'htmlOptions' => array('class' => 'form-horizontal')
            )); ?>
            <?php echo $form->errorSummary($contract); ?>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'name', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-9">
                    <?php echo $form->textField($contract, 'name', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'onblur' => "javascript:{this.value = this.value.toUpperCase(); }",
                        'value' => $contract->name
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'name'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'address', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-9">
                    <?php echo $form->textField($contract, 'address', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'value' => $contract->address
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'address'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'tax', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'tax', array(
                        'class' => 'col-xs-10 col-sm-10 tax',
                        'value' => $contract->tax
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'tax'); ?> </div>
                </div>
                <?php echo $form->labelEx($contract, 'contract', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'contract', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'onblur' => "javascript:{this.value = this.value.toUpperCase(); }",
                        'value' => $contract->getNextId() . "/" . $contract->getYear() . "/ITT-"
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'contract'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'director', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'director', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'value' => $contract->director
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'director'); ?> </div>
                </div>
                <?php echo $form->labelEx($contract, 'date', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'date', array(
                        'data-date-format' => "dd-mm-yyyy",
                        'class' => 'col-xs-10 col-sm-10 date-picker',
                        'value' => date("d-m-Y", $contract->date)
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'date'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'position', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'position', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'value' => $contract->position
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'position'); ?> </div>
                </div>
                <?php echo $form->labelEx($contract, 'tamung', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'tamung', array(
                        'class' => 'col-xs-10 col-sm-10 money',
                        'value' => $contract->tamung
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'tamung'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'marketing', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'marketing', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'value' => $contract->marketing
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'marketing'); ?> </div>
                </div>
                <?php echo $form->labelEx($contract, 'ngaygiao', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-3">
                    <?php echo $form->textField($contract, 'ngaygiao', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'value' => $contract->ngaygiao
                    )); ?> ngày
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'ngaygiao'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'note', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-9">
                    <?php echo $form->textField($contract, 'note', array(
                        'class' => 'col-xs-10 col-sm-10',
                        'value' => $contract->note
                    )); ?>
                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'note'); ?> </div>
                </div>
            </div>
            <div class="form-group">
                <?php echo $form->labelEx($contract, 'niemphong', array('class' => 'col-sm-2 control-label no-padding-right')) ?>
                <div class="col-sm-9">
                    <label><?php echo $form->checkBox($contract, 'niemphong'); ?><em>(Nếu niêm phong thì số hủy và bản
                            hủy bằng
                            0)</em></label>

                    <div
                        class="help-block col-xs-2 col-sm-reset inline"> <?php echo $form->error($contract, 'niemphong'); ?> </div>
                </div>
            </div>
            <table class="EditTable" cellspacing="1" align="center" cellpadding="2" border="0"
                   style="table-layout:fixed;width:75%;">
                <tbody>
                <tr>
                    <td><span>Niêm phong:</span></td>
                    <td colspan="3"><label><?php echo $form->checkBox($contract, 'niemphong') ?></label></td>
                </tr>
                </tbody>
            </table>
            <br>
            <table border="0" id="contract_addtable" class="table table-striped table-bordered table-hover dataTable">
                <thead>
                <tr>
                </tr>
                <tr>
                    <td align="center">STT</td>
                    <td align="center">Tên sản phẩm, hàng hóa</td>
                    <td align="center">Quy cách</td>
                    <td align="center">Đơn vị tính</td>
                    <td align="center">Số lượng</td>
                    <td align="center">Từ số</td>
                    <td align="center">Đến số</td>
                    <td align="center">Đơn giá</td>
                </tr>
                </thead>
                <tbody valign="middle">
                <tr>
                </tr>
                <tr id="tr">
                    <td id="stt" align="center">
                        <b>1</b>
                        <?php echo $form->hiddenField($product, 'order', array(
                            'name' => 'Product[0][order]',
                            'value' => 1
                        )); ?>
                    </td>
                    <td align="left">
                            <span class="inline">
                                Sản phẩm: <?php echo $form->textField($product, 'product_name', array(
                                    'size' => 25,
                                    'maxlength' => 255,
                                    'name' => 'Product[0][product_name]',
                                    'value' => "Hóa đơn GTGT"
                                )); ?>
                                <?php echo CHtml::dropDownList('Product[0][product_page]', 3, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) ?>
                                liên
                            </span>
                        <br>
                            <span class="inline">Mẫu số:
                                <?php echo $form->textField($product, 'form', array(
                                    'size' => 13,
                                    'maxlength' => 255,
                                    'name' => 'Product[0][form]',
                                    'onblur' => "javascript:{this.value = this.value.toUpperCase(); }",
                                    'value' => '01GTKT3/001'
                                )); ?>
                            </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <span class="inline">Ký hiệu:
                                <?php echo $form->textField($product, 'serial', array(
                                    'size' => 13,
                                    'maxlength' => 255,
                                    'name' => 'Product[0][serial]',
                                    'onblur' => "javascript:{this.value = this.value.toUpperCase(); }",
                                    'value' => 'AA/' . substr($contract->getYear(), -2) . 'P'
                                )); ?>
                            </span><br>

                            <span class="inline">Logo:
                                <?php echo $form->checkBox($product, 'logo', array(
                                    'name' => 'Product[0][logo]',
                                    'class' => "ace ace-switch ace-switch-3"
                                )); ?>
                                <span class="lbl"></span></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <span class="inline">Hoa văn:
                                <?php echo $form->checkBox($product, 'hoavan', array(
                                    'name' => 'Product[0][hoavan]',
                                    'class' => "ace ace-switch ace-switch-3",
                                    'checked' => 'checked'
                                )); ?>
                                <span class="lbl"></span></span><br>
                            <span class="inline">Chống ký:
                                <?php echo $form->checkBox($product, 'signed', array(
                                    'name' => 'Product[0][signed]',
                                    'class' => "ace ace-switch ace-switch-3",
                                )); ?>
                                <span class="lbl"></span></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <span class="inline">Mật mã:
                                <?php echo $form->checkBox($product, 'matma', array(
                                    'name' => 'Product[0][matma]',
                                    'class' => "ace ace-switch ace-switch-3",
                                    'checked' => 'checked'
                                )); ?>
                                <span class="lbl"></span></span>
                    </td>
                    <td align="left">
                            <span class="inline">
                                Số màu:
                                <?php echo CHtml::dropDownList('Product[0][color]', 1, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) ?>
                            </span>
                        <br>
                            <span class="inline">
                                Ruột:
                                <?php echo CHtml::dropDownList('Product[0][bowel]', 'cacbon', array('baibang' => 'Bãi Bằng', 'cacbon' => 'Cacbon', 'offset' => 'Offset')) ?>
                            </span>
                        <br>
                            <span class="inline">Kích thước:
                                <?php echo $form->textField($product, 'size', array(
                                    'size' => 10,
                                    'maxlength' => 255,
                                    'name' => 'Product[0][size]',
                                    'value' => '210 x 297mm'
                                )); ?>
                            </span>
                    </td>
                    <td align="center">
                        <?php echo CHtml::dropDownList('Product[0][unit]', 'quyen50', array('quyen50' => 'Quyển(50 số)', 'quyen100' => 'Quyển(100 số)', 'so' => 'Số', 'thung' => 'Thùng', 'to' => 'Tờ')) ?>
                    </td>
                    <td align="center">
                        <?php echo $form->textField($product, 'quantity', array(
                            'size' => 5,
                            'class' => 'money',
                            'name' => 'Product[0][quantity]',
                            'style' => 'text-align:right'
                        )); ?>
                    </td>
                    <td align="center">
                        <?php echo $form->textField($product, 'quantity_t', array(
                            'size' => 5,
                            'name' => 'Product[0][quantity_t]',
                            'style' => 'text-align:right'
                        )); ?>
                    </td>
                    <td align="center">
                        <?php echo $form->textField($product, 'quantity_d', array(
                            'size' => 5,
                            'name' => 'Product[0][quantity_d]',
                            'style' => 'text-align:right'
                        )); ?>
                    </td>
                    <td align="center">
                        <?php echo $form->textField($product, 'price', array(
                            'size' => 10,
                            'class' => 'money',
                            'name' => 'Product[0][price]',
                            'style' => 'text-align:right'
                        )); ?>
                    </td>
                </tr>
                </tbody>
            </table>
            <br>
            <table border="0" width="100%">
                <tbody>
                <tr>
                    <td align="left">
                        <input class="btn btn-sm btn-primary" id="addmore" type="button" value="Thêm sản phẩm">
                    </td>
                    <td align="right">
                        <input class="btn btn-sm btn-primary" type="submit" id="submit_add" name="submit"
                               value="Hoàn tất">&nbsp;
                    </td>
                </tr>
                </tbody>
            </table>
            <?php $this->endWidget(); ?>
        </div>
    </div>
</div>
<script>
    var count_add = 1;
    jQuery(document).on('click', '#addmore', function () {
        $.ajax({
            type: "POST",
            url: '',
            cache: false,
            data: 'more=' + count_add,
            success: function (data) {
                $('#contract_addtable tr:last').after(data);
                count_add++;
            }
        });
    });
    jQuery(document).on('click', 'a.del', function () {
        $(this).parent().parent().remove();
        count_add--;
    });
    jQuery(document).on('focus', 'input[type=text]', function () {
        this.setSelectionRange(0, this.value.length);
    });
    $('.money').mask('000,000,000,000,000', {reverse: true});
    $('.tax').mask('##########-###');
</script>